<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use think\Request;
use app\admin\model\Banner as BannerModel;
use app\admin\model\ColModel;
use app\admin\model\LabelModel;
use app\admin\model\GoodsModel;
use app\admin\model\NoticeModel;

class Index extends Controller
{   
    public function getGoods(){
        $labelid=input('labelid');  //标签id
        $data=GoodsModel::where('cid',$labelid)->order('sort asc')->where('status',1)->select();
        return json_encode(['code'=>1,'msg'=>'请求成功','data'=>$data],320);
    }
    public function getGood(){
        $id=input('id');
        $data=GoodsModel::where('id',$id)->find();
        return json_encode(['code'=>1,'msg'=>'请求成功','data'=>$data],320);
    }
    public function index(){
        $banner=BannerModel::order('sort asc')->where('status',1)->select();
        $col=ColModel::order('sort asc')->where('status',1)->select();
        $label=LabelModel::order('sort asc')->where('status',1)->select();
        $notice=NoticeModel::order('id desc')->where('status',1)->select();
        if(isset($label[0])){
            $labelid=$label[0]['id'];
            $goods=GoodsModel::where('cid',$labelid)->order('sort asc')->where('status',1)->select();
        }else{
            $goods=[];
        }
        $data=[];
        $data['banner']=$banner;
        $data['col']=$col;
        $data['label']=$label;
        $data['goods']=$goods;
        $data['notice']=$notice;
        return json_encode(['code'=>1,'msg'=>'请求成功','data'=>$data],320);
    }
    public function getsystem(){  //post field =1/2/3/4  
        $post=input('post.');
        $domain = ((int)$_SERVER['SERVER_PORT'] == 80 ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'];
        $data=Db::table('config')->find(1);
        $data['busi_img']=$domain.$data['busi_img'];
        $data['logo']=$domain.$data['logo'];
        return json_encode(['code'=>1,'msg'=>'请求成功','data'=>$data],320);
    }

    //二维数组排序
   function arraySort($array, $keys, $sort = SORT_DESC) {
        $keysValue = [];
        foreach ($array as $k => $v) {
            $keysValue[$k] = $v[$keys];
        }
        array_multisort($keysValue, $sort, $array);
        return $array;
    }
   
}
